package com.goods.controller.business;

import com.goods.business.service.IOutStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.OutStockDetailVO;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Created with IntelliJ IDEA
 *
 * @Date: 2023/3/6 - 15:28
 * @Author: Hyoung
 * @Description:
 */
@RestController
@RequestMapping("/business/outStock")
//http://www.localhost:8989/business/outStock/findOutStockList?pageNum=1&pageSize=10&status=0
public class OutStockController {


    @Autowired
    private IOutStockService iOutStockService;

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param outStockVO
     * @return
     */
    @GetMapping("/findOutStockList")
    public ResponseBean findOutStockList(@RequestParam Integer pageNum,
                                         @RequestParam Integer pageSize,
                                         OutStockVO outStockVO) {
        PageVO<OutStockVO> pageVO = iOutStockService.findOutStockList(pageNum, pageSize, outStockVO);
        return ResponseBean.success(pageVO);
    }

    /**
     * 发放明细
     *
     * @param id
     * @param pageNum
     * @return
     */
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Integer id, @RequestParam Integer pageNum) {
        OutStockDetailVO pageVO = iOutStockService.detail(id, pageNum);

        return ResponseBean.success(pageVO);
    }

    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outStockVO, @RequestHeader("Authorization") String authorization) {
        /*
        OutStockVO(id=null, outNum=null, type=0, operator=null, createTime=null, productNumber=null, priority=1, products=[{productId=56, productNumber=1}], remark=f s d fa, status=null, consumerId=null, name=11, address=北京市/市辖区/东城区, phone=15191742344, contact=1, sort=1)
         */
        String username = JWTUtils.getUsername(authorization);
        outStockVO.setOperator(username);
        iOutStockService.addOutStock(outStockVO);

        return ResponseBean.success();
    }


    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Integer id) {
        iOutStockService.delete(id);
        return ResponseBean.success();
    }

    @PutMapping("/remove/{id}")
    public ResponseBean removeOutStock(@PathVariable Integer id) {
        iOutStockService.remove(id);
        return ResponseBean.success();
    }

    @PutMapping("/back/{id}")
    public ResponseBean backOutStock(@PathVariable Integer id) {
        iOutStockService.back(id);

        return ResponseBean.success();
    }

    @PutMapping("/publish/{id}")
    public ResponseBean publishOutStock(@PathVariable Integer id) {
        iOutStockService.publish(id);

        return ResponseBean.success();
    }
}
